<template>
	<view class="user-container">
		<!-- && bindState == 1 -->
		<block v-if="notices.length > 0 ">
			<view class="cu-list menu" v-for="(notice, idx) in notices" :key="idx" :data-item="notice"
			 @click="gotoDetail(notice)">
				<view class="cu-item arrow">
					<view class="content padding-tb-sm">
						<view>
							<text class="cuIcon-notification text-cut text-green margin-right-xs"></text>
							<view class="text-cut" style="width:220px">{{notice.title}}</view>
						</view>
						<view class="text-gray text-sm">
							<text class="margin-right-xs">发布时间：</text> {{notice.publishTime}}</view>
					</view>
				</view>
			</view>
			<!-- <uni-load-more :status="loadingStatus" :content-text="loadingContentText" /> -->
		</block>
		<block v-else>
			<view class="cu-list menu">
				<view class="cu-item">
					<view class="content">
						<text class="cuIcon-notification text-grey"></text>
						<text class="text-grey">暂无公告信息</text>
					</view>
					<view class="action">
					</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	/** index.js **/
	import context from '../../lib/java110/Java110Context.js';
	const constant = context.constant; //获取app实例
	//获取app实例
	// const app = getApp().globalData;

	export default {
		data() {
			return {
				bindState:'',
				communityId: "",
				notices: [],
				currPageIndex: 0,
				pageSize: 10,
				page: 1,
				loadingStatus : 'loading',
				loadingContentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				}
			};
		},
		components: {
			uniLoadMore
		},
		onLoad: function(options) {
			let that = this;
			let countryId = uni.getStorageSync("_selectCommunity");
			this.communityId = countryId.id
			context.onLoad(options);
			// that.communityId = context.getUserInfo().communityId;
			let identity = uni.getStorageSync("bindUserInfo");
			that.bindState = identity.bindState
			that._loadNotices();
		},
		onPullDownRefresh() {
			this._loadNotices();
		},
		onShow: function() {
			let that = this;
		},
		onReachBottom : function(){
			if(this.loadingStatus == 'noMore'){
				return;
			}
		},
		methods: {
			_loadNotices: function(){
				this.loadingStatus = 'more';
				let that = this;
				uni.request({
					url: constant.url.GetNoticeListUrl,
					header: context.getHeaders(),
					method: "GET",
					data: {
						communityId: this.communityId,
					},
					success: function(res) {
						that.notices = res.data.result
					}
				});
			},
			gotoDetail: function(_notice) {
				
				// let that = this;
				console.log("_notice",_notice)
				uni.navigateTo({
					url: "/pages/notice/detail/detail?noticeId=" + JSON.stringify(_notice)
				});
			},
		}
	};
</script>
<style lang="scss" scoped>
	@import "./index.css";
	.cu-list+.cu-list {
	    margin-top: 10px;
	}
</style>
